package twitter;

import java.util.List;

import saiboten.ChannelAction;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterFactory;

public class Latterboksen implements ChannelAction {

	@Override
	public List<String> action(List<String> result, String channel,
			String sender, String message) {
		
		if (message.startsWith("!latterboksen")) {
			
			String updateText = "";
			String[] splitMessage = message.split(" ");
			
			for(String stringPiece : splitMessage) {
				if(!stringPiece.equals("!latterboksen")) {
					updateText += stringPiece + " ";
				}
			}
			try {
				Twitter twitter = new TwitterFactory().getInstance(
						"latterboksen", "rennis");
				Status status = twitter.updateStatus(updateText);
				result.add("La til tweet med innhold: " + status.getText());
			} catch (Exception u) {
				result.add("Noe gikk galt :(");
			}
		}
		return result;

	}
}
